#define _CRT_SECURE_NO_WARNINGS 1
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* intersection(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize)
{
    int hashps1[1000] = { 0 };
    int hashps2[1000] = { 0 };
    int i = 0;
    for (i = 0; i < nums1Size; i++)
    {
        hashps1[nums1[i]]++;
    }
    for (i = 0; i < nums2Size; i++)
    {
        hashps2[nums2[i]]++;
    }
    int maxlong = nums1Size > nums2Size ? nums1Size : nums2Size;
    int* ret = malloc(sizeof(int) * maxlong);
    int k = 0;
    for (i = 0; i < 1000; i++)
    {
        if (hashps1[i] != 0 && hashps2[i] != 0)
        {
            ret[k++] = i;
        }
    }
    *returnSize = k;
    return ret;
}

int dominantIndex(int* nums, int numsSize)
{
    int i = 0;
    int k = 0;
    int max = nums[0];
    for (i = 0; i < numsSize; i++)
    {
        if (nums[i] > max)
        {
            max = nums[i];
            k = i;
        }
    }
    for (i = 0; i < numsSize; i++)
    {

        if (i != k && nums[i] * 2 > max)
        {
            break;
        }
    }
    if (i == numsSize)
    {
        return k;
    }
    else
    {
        return -1;
    }
}